package com.yayan.beautyclub.service;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.yayan.beautyclub.bean.Ticket;
import com.yayan.beautyclub.dao.ITicketDao;
import com.yayan.beautyclub.dao.TicketDao;

@Service
public class TicketService implements ITicketService {

	private ITicketDao ticketDao;
	
	public TicketService(){
		ticketDao = new TicketDao();
	}
	@Override
	public List<Ticket> getTicketList(int page, int size) {
		// TODO Auto-generated method stub
		List<Ticket> list = null;
		try{
			if(page > 0 && size > 0)
				list = ticketDao.getTicketList(page, size);
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public Ticket getTicket(long tId) {
		// TODO Auto-generated method stub
		Ticket ticket = null;
		try{
			if(tId != 0L){
				ticket = ticketDao.getTicket(tId);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return ticket;
	}

	@Override
	public long save(Ticket ticket) {
		// TODO Auto-generated method stub
		long r = 0;
		try{
			if(ticket.gettName() != null && !ticket.gettName().trim().isEmpty()
					&& ticket.getStartTime() != null && ticket.getEndTime() != null){
				if(ticket.getTime() == null)
					ticket.setTime(new Date());
				r = ticketDao.save(ticket);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return r;
	}

	@Override
	public boolean update(Ticket ticket) {
		// TODO Auto-generated method stub
		boolean r = false;
		try{
			if(ticket.gettId() != 0L){
				r = ticketDao.update(ticket);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return r;
	}
	@Override
	public boolean deleteTicket(long tId) {
		// TODO Auto-generated method stub
		boolean r = false;
		try{
			if(tId != 0L){
				r = ticketDao.delete(tId);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return r;
	}

}
